//
//  HLAccount.swift
//  MyBlog
//
//  Created by 李芙蓉 on 16/3/5.
//  Copyright © 2016年 hanlei. All rights reserved.
//

import UIKit

class HLAccount: NSObject,NSCoding {
    
    var access_token : String?
    
    var profile_image_url : String?
    
    var remind_in : Int = 0
    
    var uid : Int = 0
    
    var expires_in : Double = 0
    
    var expireTime : NSDate {
 
        return NSDate().dateByAddingTimeInterval(expires_in)

    }
    
    init(dict:[String:AnyObject]) {
     
        super.init()
        
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    
    func encodeWithCoder(aCoder: NSCoder) {
        
        aCoder.encodeObject(access_token, forKey: "access_token")
        
        aCoder.encodeObject(profile_image_url, forKey: "profile_image_url")
        
        aCoder.encodeObject(expireTime, forKey: "expireTime")
        
        aCoder.encodeInteger(remind_in, forKey: "remind_in")
        
        aCoder.encodeInteger(uid, forKey: "uid")
        
        aCoder.encodeDouble(expires_in, forKey: "expires_in")
    }
    
    required init?(coder aDecoder: NSCoder) {
        
        aDecoder.decodeObjectForKey("access_token")
        
        aDecoder.decodeObjectForKey("access_token")
        
        aDecoder.decodeObjectForKey("access_token")
        
        aDecoder.decodeIntegerForKey("remind_in")
        
        aDecoder.decodeIntegerForKey("uid")
        
        aDecoder.decodeDoubleForKey("expires_in")
    }

}
